
USE [MetropasWeb]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Activity table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Get_List

AS


				
				SELECT
					[Id],
					[SessionId],
					[UserId],
					[Ip],
					[DateLogin],
					[DateLogout],
					[Description]
				FROM
					[dbo].[Activity]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Activity table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Activity]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[SessionId], O.[UserId], O.[Ip], O.[DateLogin], O.[DateLogout], O.[Description]
				FROM
				    [dbo].[Activity] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Activity]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Activity table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Insert
(

	@Id int    OUTPUT,

	@SessionId nvarchar (50)  ,

	@UserId int   ,

	@Ip nvarchar (50)  ,

	@DateLogin datetime   ,

	@DateLogout datetime   ,

	@Description nvarchar (150)  
)
AS


				
				INSERT INTO [dbo].[Activity]
					(
					[SessionId]
					,[UserId]
					,[Ip]
					,[DateLogin]
					,[DateLogout]
					,[Description]
					)
				VALUES
					(
					@SessionId
					,@UserId
					,@Ip
					,@DateLogin
					,@DateLogout
					,@Description
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Activity table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Update
(

	@Id int   ,

	@SessionId nvarchar (50)  ,

	@UserId int   ,

	@Ip nvarchar (50)  ,

	@DateLogin datetime   ,

	@DateLogout datetime   ,

	@Description nvarchar (150)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Activity]
				SET
					[SessionId] = @SessionId
					,[UserId] = @UserId
					,[Ip] = @Ip
					,[DateLogin] = @DateLogin
					,[DateLogout] = @DateLogout
					,[Description] = @Description
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Activity table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Activity] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_GetByUserId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_GetByUserId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_GetByUserId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Activity table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_GetByUserId
(

	@UserId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[SessionId],
					[UserId],
					[Ip],
					[DateLogin],
					[DateLogout],
					[Description]
				FROM
					[dbo].[Activity]
				WHERE
					[UserId] = @UserId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_GetBySessionId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_GetBySessionId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_GetBySessionId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Activity table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_GetBySessionId
(

	@SessionId nvarchar (50)  
)
AS


				SELECT
					[Id],
					[SessionId],
					[UserId],
					[Ip],
					[DateLogin],
					[DateLogout],
					[Description]
				FROM
					[dbo].[Activity]
				WHERE
					[SessionId] = @SessionId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Activity table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[SessionId],
					[UserId],
					[Ip],
					[DateLogin],
					[DateLogout],
					[Description]
				FROM
					[dbo].[Activity]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Activity_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Activity_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Activity_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Activity table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Activity_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@SessionId nvarchar (50)  = null ,

	@UserId int   = null ,

	@Ip nvarchar (50)  = null ,

	@DateLogin datetime   = null ,

	@DateLogout datetime   = null ,

	@Description nvarchar (150)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [SessionId]
	, [UserId]
	, [Ip]
	, [DateLogin]
	, [DateLogout]
	, [Description]
    FROM
	[dbo].[Activity]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([SessionId] = @SessionId OR @SessionId IS NULL)
	AND ([UserId] = @UserId OR @UserId IS NULL)
	AND ([Ip] = @Ip OR @Ip IS NULL)
	AND ([DateLogin] = @DateLogin OR @DateLogin IS NULL)
	AND ([DateLogout] = @DateLogout OR @DateLogout IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [SessionId]
	, [UserId]
	, [Ip]
	, [DateLogin]
	, [DateLogout]
	, [Description]
    FROM
	[dbo].[Activity]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([SessionId] = @SessionId AND @SessionId is not null)
	OR ([UserId] = @UserId AND @UserId is not null)
	OR ([Ip] = @Ip AND @Ip is not null)
	OR ([DateLogin] = @DateLogin AND @DateLogin is not null)
	OR ([DateLogout] = @DateLogout AND @DateLogout is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Setting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Get_List

AS


				
				SELECT
					[SettingName],
					[SettingValue],
					[DataType],
					[Description]
				FROM
					[dbo].[Setting]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Setting table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [SettingName] nvarchar(50)  
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([SettingName])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [SettingName]'
				SET @SQL = @SQL + ' FROM [dbo].[Setting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[SettingName], O.[SettingValue], O.[DataType], O.[Description]
				FROM
				    [dbo].[Setting] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[SettingName] = PageIndex.[SettingName]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Setting]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Setting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Insert
(

	@SettingName nvarchar (50)  ,

	@SettingValue nvarchar (50)  ,

	@DataType nchar (10)  ,

	@Description nchar (10)  
)
AS


				
				INSERT INTO [dbo].[Setting]
					(
					[SettingName]
					,[SettingValue]
					,[DataType]
					,[Description]
					)
				VALUES
					(
					@SettingName
					,@SettingValue
					,@DataType
					,@Description
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Setting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Update
(

	@SettingName nvarchar (50)  ,

	@OriginalSettingName nvarchar (50)  ,

	@SettingValue nvarchar (50)  ,

	@DataType nchar (10)  ,

	@Description nchar (10)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Setting]
				SET
					[SettingName] = @SettingName
					,[SettingValue] = @SettingValue
					,[DataType] = @DataType
					,[Description] = @Description
				WHERE
[SettingName] = @OriginalSettingName 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Setting table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Delete
(

	@SettingName nvarchar (50)  
)
AS


				DELETE FROM [dbo].[Setting] WITH (ROWLOCK) 
				WHERE
					[SettingName] = @SettingName
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_GetBySettingName procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_GetBySettingName') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_GetBySettingName
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Setting table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_GetBySettingName
(

	@SettingName nvarchar (50)  
)
AS


				SELECT
					[SettingName],
					[SettingValue],
					[DataType],
					[Description]
				FROM
					[dbo].[Setting]
				WHERE
					[SettingName] = @SettingName
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Setting_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Setting_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Setting_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Setting table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Setting_Find
(

	@SearchUsingOR bit   = null ,

	@SettingName nvarchar (50)  = null ,

	@SettingValue nvarchar (50)  = null ,

	@DataType nchar (10)  = null ,

	@Description nchar (10)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
	, [DataType]
	, [Description]
    FROM
	[dbo].[Setting]
    WHERE 
	 ([SettingName] = @SettingName OR @SettingName IS NULL)
	AND ([SettingValue] = @SettingValue OR @SettingValue IS NULL)
	AND ([DataType] = @DataType OR @DataType IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [SettingName]
	, [SettingValue]
	, [DataType]
	, [Description]
    FROM
	[dbo].[Setting]
    WHERE 
	 ([SettingName] = @SettingName AND @SettingName is not null)
	OR ([SettingValue] = @SettingValue AND @SettingValue is not null)
	OR ([DataType] = @DataType AND @DataType is not null)
	OR ([Description] = @Description AND @Description is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the SlideType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_Get_List

AS


				
				SELECT
					[Id],
					[Title]
				FROM
					[dbo].[SlideType]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the SlideType table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[SlideType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Title]
				FROM
				    [dbo].[SlideType] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[SlideType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the SlideType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_Insert
(

	@Id int    OUTPUT,

	@Title nvarchar (50)  
)
AS


				
				INSERT INTO [dbo].[SlideType]
					(
					[Title]
					)
				VALUES
					(
					@Title
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the SlideType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_Update
(

	@Id int   ,

	@Title nvarchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[SlideType]
				SET
					[Title] = @Title
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the SlideType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[SlideType] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the SlideType table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Title]
				FROM
					[dbo].[SlideType]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.SlideType_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.SlideType_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.SlideType_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the SlideType table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.SlideType_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Title nvarchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Title]
    FROM
	[dbo].[SlideType]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Title]
    FROM
	[dbo].[SlideType]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Title] = @Title AND @Title is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the UserAccount table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Get_List

AS


				
				SELECT
					[Id],
					[Username],
					[Title],
					[FirstName],
					[LastName],
					[Password],
					[PasswordSalt],
					[LastLogin],
					[UserType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsActivity]
				FROM
					[dbo].[UserAccount]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the UserAccount table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[UserAccount]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Username], O.[Title], O.[FirstName], O.[LastName], O.[Password], O.[PasswordSalt], O.[LastLogin], O.[UserType], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser], O.[IsActivity]
				FROM
				    [dbo].[UserAccount] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[UserAccount]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the UserAccount table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Insert
(

	@Id int    OUTPUT,

	@Username varchar (50)  ,

	@Title nvarchar (20)  ,

	@FirstName nvarchar (50)  ,

	@LastName nvarchar (50)  ,

	@Password nvarchar (50)  ,

	@PasswordSalt nvarchar (50)  ,

	@LastLogin datetime   ,

	@UserType int   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsActivity bit   
)
AS


				
				INSERT INTO [dbo].[UserAccount]
					(
					[Username]
					,[Title]
					,[FirstName]
					,[LastName]
					,[Password]
					,[PasswordSalt]
					,[LastLogin]
					,[UserType]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					,[IsActivity]
					)
				VALUES
					(
					@Username
					,@Title
					,@FirstName
					,@LastName
					,@Password
					,@PasswordSalt
					,@LastLogin
					,@UserType
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					,@IsActivity
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the UserAccount table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Update
(

	@Id int   ,

	@Username varchar (50)  ,

	@Title nvarchar (20)  ,

	@FirstName nvarchar (50)  ,

	@LastName nvarchar (50)  ,

	@Password nvarchar (50)  ,

	@PasswordSalt nvarchar (50)  ,

	@LastLogin datetime   ,

	@UserType int   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsActivity bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[UserAccount]
				SET
					[Username] = @Username
					,[Title] = @Title
					,[FirstName] = @FirstName
					,[LastName] = @LastName
					,[Password] = @Password
					,[PasswordSalt] = @PasswordSalt
					,[LastLogin] = @LastLogin
					,[UserType] = @UserType
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
					,[IsActivity] = @IsActivity
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the UserAccount table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[UserAccount] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_GetByUserType procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_GetByUserType') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_GetByUserType
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserAccount table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_GetByUserType
(

	@UserType int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Username],
					[Title],
					[FirstName],
					[LastName],
					[Password],
					[PasswordSalt],
					[LastLogin],
					[UserType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsActivity]
				FROM
					[dbo].[UserAccount]
				WHERE
					[UserType] = @UserType
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_GetByUsername procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_GetByUsername') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_GetByUsername
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserAccount table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_GetByUsername
(

	@Username varchar (50)  
)
AS


				SELECT
					[Id],
					[Username],
					[Title],
					[FirstName],
					[LastName],
					[Password],
					[PasswordSalt],
					[LastLogin],
					[UserType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsActivity]
				FROM
					[dbo].[UserAccount]
				WHERE
					[Username] = @Username
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserAccount table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Username],
					[Title],
					[FirstName],
					[LastName],
					[Password],
					[PasswordSalt],
					[LastLogin],
					[UserType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsActivity]
				FROM
					[dbo].[UserAccount]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserAccount_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserAccount_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserAccount_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the UserAccount table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserAccount_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Username varchar (50)  = null ,

	@Title nvarchar (20)  = null ,

	@FirstName nvarchar (50)  = null ,

	@LastName nvarchar (50)  = null ,

	@Password nvarchar (50)  = null ,

	@PasswordSalt nvarchar (50)  = null ,

	@LastLogin datetime   = null ,

	@UserType int   = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null ,

	@IsActivity bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [Title]
	, [FirstName]
	, [LastName]
	, [Password]
	, [PasswordSalt]
	, [LastLogin]
	, [UserType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsActivity]
    FROM
	[dbo].[UserAccount]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Username] = @Username OR @Username IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([FirstName] = @FirstName OR @FirstName IS NULL)
	AND ([LastName] = @LastName OR @LastName IS NULL)
	AND ([Password] = @Password OR @Password IS NULL)
	AND ([PasswordSalt] = @PasswordSalt OR @PasswordSalt IS NULL)
	AND ([LastLogin] = @LastLogin OR @LastLogin IS NULL)
	AND ([UserType] = @UserType OR @UserType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
	AND ([IsActivity] = @IsActivity OR @IsActivity IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Username]
	, [Title]
	, [FirstName]
	, [LastName]
	, [Password]
	, [PasswordSalt]
	, [LastLogin]
	, [UserType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsActivity]
    FROM
	[dbo].[UserAccount]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Username] = @Username AND @Username is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([FirstName] = @FirstName AND @FirstName is not null)
	OR ([LastName] = @LastName AND @LastName is not null)
	OR ([Password] = @Password AND @Password is not null)
	OR ([PasswordSalt] = @PasswordSalt AND @PasswordSalt is not null)
	OR ([LastLogin] = @LastLogin AND @LastLogin is not null)
	OR ([UserType] = @UserType AND @UserType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	OR ([IsActivity] = @IsActivity AND @IsActivity is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the tblSettings table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_Get_List

AS


				
				SELECT
					[ID],
					[Type],
					[Code],
					[ValueString],
					[ValueBinary]
				FROM
					[dbo].[tblSettings]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the tblSettings table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [ID] uniqueidentifier 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([ID])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [ID]'
				SET @SQL = @SQL + ' FROM [dbo].[tblSettings]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[ID], O.[Type], O.[Code], O.[ValueString], O.[ValueBinary]
				FROM
				    [dbo].[tblSettings] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[ID] = PageIndex.[ID]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[tblSettings]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the tblSettings table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_Insert
(

	@Id uniqueidentifier    OUTPUT,

	@Type tinyint   ,

	@Code nvarchar (50)  ,

	@ValueString nvarchar (MAX)  ,

	@ValueBinary varbinary (MAX)  
)
AS


				
				INSERT INTO [dbo].[tblSettings]
					(
					[ID]
					,[Type]
					,[Code]
					,[ValueString]
					,[ValueBinary]
					)
				VALUES
					(
					@Id
					,@Type
					,@Code
					,@ValueString
					,@ValueBinary
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the tblSettings table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_Update
(

	@Id uniqueidentifier   ,

	@OriginalId uniqueidentifier   ,

	@Type tinyint   ,

	@Code nvarchar (50)  ,

	@ValueString nvarchar (MAX)  ,

	@ValueBinary varbinary (MAX)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[tblSettings]
				SET
					[ID] = @Id
					,[Type] = @Type
					,[Code] = @Code
					,[ValueString] = @ValueString
					,[ValueBinary] = @ValueBinary
				WHERE
[ID] = @OriginalId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the tblSettings table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_Delete
(

	@Id uniqueidentifier   
)
AS


				DELETE FROM [dbo].[tblSettings] WITH (ROWLOCK) 
				WHERE
					[ID] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_GetByCode procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_GetByCode') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_GetByCode
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSettings table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_GetByCode
(

	@Code nvarchar (50)  
)
AS


				SELECT
					[ID],
					[Type],
					[Code],
					[ValueString],
					[ValueBinary]
				FROM
					[dbo].[tblSettings]
				WHERE
					[Code] = @Code
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the tblSettings table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_GetById
(

	@Id uniqueidentifier   
)
AS


				SELECT
					[ID],
					[Type],
					[Code],
					[ValueString],
					[ValueBinary]
				FROM
					[dbo].[tblSettings]
				WHERE
					[ID] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.tblSettings_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.tblSettings_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.tblSettings_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the tblSettings table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.tblSettings_Find
(

	@SearchUsingOR bit   = null ,

	@Id uniqueidentifier   = null ,

	@Type tinyint   = null ,

	@Code nvarchar (50)  = null ,

	@ValueString nvarchar (MAX)  = null ,

	@ValueBinary varbinary (MAX)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [ID]
	, [Type]
	, [Code]
	, [ValueString]
	, [ValueBinary]
    FROM
	[dbo].[tblSettings]
    WHERE 
	 ([ID] = @Id OR @Id IS NULL)
	AND ([Type] = @Type OR @Type IS NULL)
	AND ([Code] = @Code OR @Code IS NULL)
	AND ([ValueString] = @ValueString OR @ValueString IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [ID]
	, [Type]
	, [Code]
	, [ValueString]
	, [ValueBinary]
    FROM
	[dbo].[tblSettings]
    WHERE 
	 ([ID] = @Id AND @Id is not null)
	OR ([Type] = @Type AND @Type is not null)
	OR ([Code] = @Code AND @Code is not null)
	OR ([ValueString] = @ValueString AND @ValueString is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the MessageConfig table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Get_List

AS


				
				SELECT
					[KeyCode],
					[Language],
					[Value],
					[TypeId],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[MessageConfig]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the MessageConfig table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [KeyCode] varchar(15) , [Language] varchar(10)  
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([KeyCode], [Language])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [KeyCode], [Language]'
				SET @SQL = @SQL + ' FROM [dbo].[MessageConfig]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[KeyCode], O.[Language], O.[Value], O.[TypeId], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser]
				FROM
				    [dbo].[MessageConfig] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[KeyCode] = PageIndex.[KeyCode]
					AND O.[Language] = PageIndex.[Language]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[MessageConfig]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the MessageConfig table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Insert
(

	@KeyCode varchar (15)  ,

	@Language varchar (10)  ,

	@Value nvarchar (200)  ,

	@TypeId int   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				INSERT INTO [dbo].[MessageConfig]
					(
					[KeyCode]
					,[Language]
					,[Value]
					,[TypeId]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					)
				VALUES
					(
					@KeyCode
					,@Language
					,@Value
					,@TypeId
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the MessageConfig table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Update
(

	@KeyCode varchar (15)  ,

	@OriginalKeyCode varchar (15)  ,

	@Language varchar (10)  ,

	@OriginalLanguage varchar (10)  ,

	@Value nvarchar (200)  ,

	@TypeId int   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[MessageConfig]
				SET
					[KeyCode] = @KeyCode
					,[Language] = @Language
					,[Value] = @Value
					,[TypeId] = @TypeId
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
				WHERE
[KeyCode] = @OriginalKeyCode 
AND [Language] = @OriginalLanguage 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the MessageConfig table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Delete
(

	@KeyCode varchar (15)  ,

	@Language varchar (10)  
)
AS


				DELETE FROM [dbo].[MessageConfig] WITH (ROWLOCK) 
				WHERE
					[KeyCode] = @KeyCode
					AND [Language] = @Language
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_GetByKeyCodeLanguage procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_GetByKeyCodeLanguage') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_GetByKeyCodeLanguage
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the MessageConfig table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_GetByKeyCodeLanguage
(

	@KeyCode varchar (15)  ,

	@Language varchar (10)  
)
AS


				SELECT
					[KeyCode],
					[Language],
					[Value],
					[TypeId],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[MessageConfig]
				WHERE
					[KeyCode] = @KeyCode
					AND [Language] = @Language
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.MessageConfig_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.MessageConfig_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.MessageConfig_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the MessageConfig table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.MessageConfig_Find
(

	@SearchUsingOR bit   = null ,

	@KeyCode varchar (15)  = null ,

	@Language varchar (10)  = null ,

	@Value nvarchar (200)  = null ,

	@TypeId int   = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [KeyCode]
	, [Language]
	, [Value]
	, [TypeId]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[MessageConfig]
    WHERE 
	 ([KeyCode] = @KeyCode OR @KeyCode IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([Value] = @Value OR @Value IS NULL)
	AND ([TypeId] = @TypeId OR @TypeId IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [KeyCode]
	, [Language]
	, [Value]
	, [TypeId]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[MessageConfig]
    WHERE 
	 ([KeyCode] = @KeyCode AND @KeyCode is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([Value] = @Value AND @Value is not null)
	OR ([TypeId] = @TypeId AND @TypeId is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Slide table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_Get_List

AS


				
				SELECT
					[Id],
					[Url],
					[Title],
					[DataType],
					[Description],
					[Thumbnail],
					[OrderIndex],
					[Language]
				FROM
					[dbo].[Slide]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Slide table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Slide]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Url], O.[Title], O.[DataType], O.[Description], O.[Thumbnail], O.[OrderIndex], O.[Language]
				FROM
				    [dbo].[Slide] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Slide]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Slide table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_Insert
(

	@Id int    OUTPUT,

	@Url nvarchar (150)  ,

	@Title nvarchar (150)  ,

	@DataType int   ,

	@Description nvarchar (500)  ,

	@Thumbnail varchar (200)  ,

	@OrderIndex int   ,

	@Language varchar (10)  
)
AS


				
				INSERT INTO [dbo].[Slide]
					(
					[Url]
					,[Title]
					,[DataType]
					,[Description]
					,[Thumbnail]
					,[OrderIndex]
					,[Language]
					)
				VALUES
					(
					@Url
					,@Title
					,@DataType
					,@Description
					,@Thumbnail
					,@OrderIndex
					,@Language
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Slide table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_Update
(

	@Id int   ,

	@Url nvarchar (150)  ,

	@Title nvarchar (150)  ,

	@DataType int   ,

	@Description nvarchar (500)  ,

	@Thumbnail varchar (200)  ,

	@OrderIndex int   ,

	@Language varchar (10)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Slide]
				SET
					[Url] = @Url
					,[Title] = @Title
					,[DataType] = @DataType
					,[Description] = @Description
					,[Thumbnail] = @Thumbnail
					,[OrderIndex] = @OrderIndex
					,[Language] = @Language
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Slide table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Slide] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_GetByDataType procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_GetByDataType') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_GetByDataType
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Slide table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_GetByDataType
(

	@DataType int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[Url],
					[Title],
					[DataType],
					[Description],
					[Thumbnail],
					[OrderIndex],
					[Language]
				FROM
					[dbo].[Slide]
				WHERE
					[DataType] = @DataType
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Slide table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Url],
					[Title],
					[DataType],
					[Description],
					[Thumbnail],
					[OrderIndex],
					[Language]
				FROM
					[dbo].[Slide]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Slide_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Slide_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Slide_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Slide table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Slide_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Url nvarchar (150)  = null ,

	@Title nvarchar (150)  = null ,

	@DataType int   = null ,

	@Description nvarchar (500)  = null ,

	@Thumbnail varchar (200)  = null ,

	@OrderIndex int   = null ,

	@Language varchar (10)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [DataType]
	, [Description]
	, [Thumbnail]
	, [OrderIndex]
	, [Language]
    FROM
	[dbo].[Slide]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Url] = @Url OR @Url IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([DataType] = @DataType OR @DataType IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([Thumbnail] = @Thumbnail OR @Thumbnail IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [DataType]
	, [Description]
	, [Thumbnail]
	, [OrderIndex]
	, [Language]
    FROM
	[dbo].[Slide]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Url] = @Url AND @Url is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([DataType] = @DataType AND @DataType is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Thumbnail] = @Thumbnail AND @Thumbnail is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([Language] = @Language AND @Language is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Menu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_Get_List

AS


				
				SELECT
					[Id],
					[Title],
					[Alias],
					[Link],
					[ParentId],
					[OrderIndex],
					[IsVisible],
					[MenuType],
					[MenuPosition],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Menu]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Menu table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Menu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Title], O.[Alias], O.[Link], O.[ParentId], O.[OrderIndex], O.[IsVisible], O.[MenuType], O.[MenuPosition], O.[Language], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser]
				FROM
				    [dbo].[Menu] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Menu]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Menu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_Insert
(

	@Id int    OUTPUT,

	@Title nvarchar (200)  ,

	@Alias varchar (200)  ,

	@Link nvarchar (200)  ,

	@ParentId int   ,

	@OrderIndex int   ,

	@IsVisible bit   ,

	@MenuType varchar (10)  ,

	@MenuPosition varchar (10)  ,

	@Language varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				INSERT INTO [dbo].[Menu]
					(
					[Title]
					,[Alias]
					,[Link]
					,[ParentId]
					,[OrderIndex]
					,[IsVisible]
					,[MenuType]
					,[MenuPosition]
					,[Language]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					)
				VALUES
					(
					@Title
					,@Alias
					,@Link
					,@ParentId
					,@OrderIndex
					,@IsVisible
					,@MenuType
					,@MenuPosition
					,@Language
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Menu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_Update
(

	@Id int   ,

	@Title nvarchar (200)  ,

	@Alias varchar (200)  ,

	@Link nvarchar (200)  ,

	@ParentId int   ,

	@OrderIndex int   ,

	@IsVisible bit   ,

	@MenuType varchar (10)  ,

	@MenuPosition varchar (10)  ,

	@Language varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Menu]
				SET
					[Title] = @Title
					,[Alias] = @Alias
					,[Link] = @Link
					,[ParentId] = @ParentId
					,[OrderIndex] = @OrderIndex
					,[IsVisible] = @IsVisible
					,[MenuType] = @MenuType
					,[MenuPosition] = @MenuPosition
					,[Language] = @Language
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Menu table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Menu] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_GetByAlias procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_GetByAlias') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_GetByAlias
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Menu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_GetByAlias
(

	@Alias varchar (200)  
)
AS


				SELECT
					[Id],
					[Title],
					[Alias],
					[Link],
					[ParentId],
					[OrderIndex],
					[IsVisible],
					[MenuType],
					[MenuPosition],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Menu]
				WHERE
					[Alias] = @Alias
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Menu table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Title],
					[Alias],
					[Link],
					[ParentId],
					[OrderIndex],
					[IsVisible],
					[MenuType],
					[MenuPosition],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Menu]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Menu_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Menu_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Menu_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Menu table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Menu_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Title nvarchar (200)  = null ,

	@Alias varchar (200)  = null ,

	@Link nvarchar (200)  = null ,

	@ParentId int   = null ,

	@OrderIndex int   = null ,

	@IsVisible bit   = null ,

	@MenuType varchar (10)  = null ,

	@MenuPosition varchar (10)  = null ,

	@Language varchar (10)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Title]
	, [Alias]
	, [Link]
	, [ParentId]
	, [OrderIndex]
	, [IsVisible]
	, [MenuType]
	, [MenuPosition]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Menu]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Alias] = @Alias OR @Alias IS NULL)
	AND ([Link] = @Link OR @Link IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsVisible] = @IsVisible OR @IsVisible IS NULL)
	AND ([MenuType] = @MenuType OR @MenuType IS NULL)
	AND ([MenuPosition] = @MenuPosition OR @MenuPosition IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Title]
	, [Alias]
	, [Link]
	, [ParentId]
	, [OrderIndex]
	, [IsVisible]
	, [MenuType]
	, [MenuPosition]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Menu]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Alias] = @Alias AND @Alias is not null)
	OR ([Link] = @Link AND @Link is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsVisible] = @IsVisible AND @IsVisible is not null)
	OR ([MenuType] = @MenuType AND @MenuType is not null)
	OR ([MenuPosition] = @MenuPosition AND @MenuPosition is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Hospital table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Get_List

AS


				
				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Introduction],
					[Thumbnail],
					[ClinicTime],
					[Contact],
					[Price],
					[Process],
					[OrderIndex],
					[IsVisible],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Hospital]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Hospital table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Hospital]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[LocalId], O.[Title], O.[Alias], O.[Introduction], O.[Thumbnail], O.[ClinicTime], O.[Contact], O.[Price], O.[Process], O.[OrderIndex], O.[IsVisible], O.[Language], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser]
				FROM
				    [dbo].[Hospital] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Hospital]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Hospital table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Insert
(

	@Id int    OUTPUT,

	@LocalId nvarchar (20)  ,

	@Title nvarchar (50)  ,

	@Alias nvarchar (50)  ,

	@Introduction ntext   ,

	@Thumbnail varchar (200)  ,

	@ClinicTime ntext   ,

	@Contact ntext   ,

	@Price ntext   ,

	@Process ntext   ,

	@OrderIndex int   ,

	@IsVisible bit   ,

	@Language varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				INSERT INTO [dbo].[Hospital]
					(
					[LocalId]
					,[Title]
					,[Alias]
					,[Introduction]
					,[Thumbnail]
					,[ClinicTime]
					,[Contact]
					,[Price]
					,[Process]
					,[OrderIndex]
					,[IsVisible]
					,[Language]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					)
				VALUES
					(
					@LocalId
					,@Title
					,@Alias
					,@Introduction
					,@Thumbnail
					,@ClinicTime
					,@Contact
					,@Price
					,@Process
					,@OrderIndex
					,@IsVisible
					,@Language
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Hospital table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Update
(

	@Id int   ,

	@LocalId nvarchar (20)  ,

	@Title nvarchar (50)  ,

	@Alias nvarchar (50)  ,

	@Introduction ntext   ,

	@Thumbnail varchar (200)  ,

	@ClinicTime ntext   ,

	@Contact ntext   ,

	@Price ntext   ,

	@Process ntext   ,

	@OrderIndex int   ,

	@IsVisible bit   ,

	@Language varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Hospital]
				SET
					[LocalId] = @LocalId
					,[Title] = @Title
					,[Alias] = @Alias
					,[Introduction] = @Introduction
					,[Thumbnail] = @Thumbnail
					,[ClinicTime] = @ClinicTime
					,[Contact] = @Contact
					,[Price] = @Price
					,[Process] = @Process
					,[OrderIndex] = @OrderIndex
					,[IsVisible] = @IsVisible
					,[Language] = @Language
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Hospital table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Hospital] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_GetByAlias procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_GetByAlias') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_GetByAlias
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Hospital table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_GetByAlias
(

	@Alias nvarchar (50)  
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Introduction],
					[Thumbnail],
					[ClinicTime],
					[Contact],
					[Price],
					[Process],
					[OrderIndex],
					[IsVisible],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Hospital]
				WHERE
					[Alias] = @Alias
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_GetByLocalId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_GetByLocalId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_GetByLocalId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Hospital table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_GetByLocalId
(

	@LocalId nvarchar (20)  
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Introduction],
					[Thumbnail],
					[ClinicTime],
					[Contact],
					[Price],
					[Process],
					[OrderIndex],
					[IsVisible],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Hospital]
				WHERE
					[LocalId] = @LocalId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Hospital table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Introduction],
					[Thumbnail],
					[ClinicTime],
					[Contact],
					[Price],
					[Process],
					[OrderIndex],
					[IsVisible],
					[Language],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser]
				FROM
					[dbo].[Hospital]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Hospital_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Hospital_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Hospital_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Hospital table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Hospital_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LocalId nvarchar (20)  = null ,

	@Title nvarchar (50)  = null ,

	@Alias nvarchar (50)  = null ,

	@Introduction ntext   = null ,

	@Thumbnail varchar (200)  = null ,

	@ClinicTime ntext   = null ,

	@Contact ntext   = null ,

	@Price ntext   = null ,

	@Process ntext   = null ,

	@OrderIndex int   = null ,

	@IsVisible bit   = null ,

	@Language varchar (10)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Introduction]
	, [Thumbnail]
	, [ClinicTime]
	, [Contact]
	, [Price]
	, [Process]
	, [OrderIndex]
	, [IsVisible]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Hospital]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LocalId] = @LocalId OR @LocalId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Alias] = @Alias OR @Alias IS NULL)
	AND ([Thumbnail] = @Thumbnail OR @Thumbnail IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsVisible] = @IsVisible OR @IsVisible IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Introduction]
	, [Thumbnail]
	, [ClinicTime]
	, [Contact]
	, [Price]
	, [Process]
	, [OrderIndex]
	, [IsVisible]
	, [Language]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
    FROM
	[dbo].[Hospital]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LocalId] = @LocalId AND @LocalId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Alias] = @Alias AND @Alias is not null)
	OR ([Thumbnail] = @Thumbnail AND @Thumbnail is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsVisible] = @IsVisible AND @IsVisible is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Appointment table
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_Get_List

AS


				
				SELECT
					[Id],
					[LocalId],
					[FirstName],
					[LastName],
					[FromTime],
					[EndTime],
					[Description],
					[Doctor],
					[ParentId],
					[AppointmentType],
					[CreatedDate]
				FROM
					[dbo].[Appointment]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Appointment table passing page index and page count parameters
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Appointment]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[LocalId], O.[FirstName], O.[LastName], O.[FromTime], O.[EndTime], O.[Description], O.[Doctor], O.[ParentId], O.[AppointmentType], O.[CreatedDate]
				FROM
				    [dbo].[Appointment] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Appointment]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Appointment table
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_Insert
(

	@Id int    OUTPUT,

	@LocalId nvarchar (20)  ,

	@FirstName nvarchar (50)  ,

	@LastName nvarchar (50)  ,

	@FromTime datetime   ,

	@EndTime datetime   ,

	@Description nvarchar (500)  ,

	@Doctor nvarchar (100)  ,

	@ParentId varchar (15)  ,

	@AppointmentType varchar (20)  ,

	@CreatedDate datetime   
)
AS


				
				INSERT INTO [dbo].[Appointment]
					(
					[LocalId]
					,[FirstName]
					,[LastName]
					,[FromTime]
					,[EndTime]
					,[Description]
					,[Doctor]
					,[ParentId]
					,[AppointmentType]
					,[CreatedDate]
					)
				VALUES
					(
					@LocalId
					,@FirstName
					,@LastName
					,@FromTime
					,@EndTime
					,@Description
					,@Doctor
					,@ParentId
					,@AppointmentType
					,@CreatedDate
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Appointment table
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_Update
(

	@Id int   ,

	@LocalId nvarchar (20)  ,

	@FirstName nvarchar (50)  ,

	@LastName nvarchar (50)  ,

	@FromTime datetime   ,

	@EndTime datetime   ,

	@Description nvarchar (500)  ,

	@Doctor nvarchar (100)  ,

	@ParentId varchar (15)  ,

	@AppointmentType varchar (20)  ,

	@CreatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Appointment]
				SET
					[LocalId] = @LocalId
					,[FirstName] = @FirstName
					,[LastName] = @LastName
					,[FromTime] = @FromTime
					,[EndTime] = @EndTime
					,[Description] = @Description
					,[Doctor] = @Doctor
					,[ParentId] = @ParentId
					,[AppointmentType] = @AppointmentType
					,[CreatedDate] = @CreatedDate
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Appointment table
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Appointment] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Appointment table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[LocalId],
					[FirstName],
					[LastName],
					[FromTime],
					[EndTime],
					[Description],
					[Doctor],
					[ParentId],
					[AppointmentType],
					[CreatedDate]
				FROM
					[dbo].[Appointment]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Appointment_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Appointment_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Appointment_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Appointment table passing nullable parameters
-- Table Comment: Đặt lịch hẹn
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Appointment_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LocalId nvarchar (20)  = null ,

	@FirstName nvarchar (50)  = null ,

	@LastName nvarchar (50)  = null ,

	@FromTime datetime   = null ,

	@EndTime datetime   = null ,

	@Description nvarchar (500)  = null ,

	@Doctor nvarchar (100)  = null ,

	@ParentId varchar (15)  = null ,

	@AppointmentType varchar (20)  = null ,

	@CreatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [FirstName]
	, [LastName]
	, [FromTime]
	, [EndTime]
	, [Description]
	, [Doctor]
	, [ParentId]
	, [AppointmentType]
	, [CreatedDate]
    FROM
	[dbo].[Appointment]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LocalId] = @LocalId OR @LocalId IS NULL)
	AND ([FirstName] = @FirstName OR @FirstName IS NULL)
	AND ([LastName] = @LastName OR @LastName IS NULL)
	AND ([FromTime] = @FromTime OR @FromTime IS NULL)
	AND ([EndTime] = @EndTime OR @EndTime IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([Doctor] = @Doctor OR @Doctor IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([AppointmentType] = @AppointmentType OR @AppointmentType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [FirstName]
	, [LastName]
	, [FromTime]
	, [EndTime]
	, [Description]
	, [Doctor]
	, [ParentId]
	, [AppointmentType]
	, [CreatedDate]
    FROM
	[dbo].[Appointment]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LocalId] = @LocalId AND @LocalId is not null)
	OR ([FirstName] = @FirstName AND @FirstName is not null)
	OR ([LastName] = @LastName AND @LastName is not null)
	OR ([FromTime] = @FromTime AND @FromTime is not null)
	OR ([EndTime] = @EndTime AND @EndTime is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([Doctor] = @Doctor AND @Doctor is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([AppointmentType] = @AppointmentType AND @AppointmentType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Article table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Get_List

AS


				
				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Summary],
					[Description],
					[MenuId],
					[Thumbnail],
					[IsPublished],
					[OrderIndex],
					[IsAllowDelete],
					[Language],
					[PublishedDate],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsHot]
				FROM
					[dbo].[Article]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Article table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Article]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[LocalId], O.[Title], O.[Alias], O.[Summary], O.[Description], O.[MenuId], O.[Thumbnail], O.[IsPublished], O.[OrderIndex], O.[IsAllowDelete], O.[Language], O.[PublishedDate], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser], O.[IsHot]
				FROM
				    [dbo].[Article] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Article]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Article table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Insert
(

	@Id int    OUTPUT,

	@LocalId nvarchar (20)  ,

	@Title nvarchar (200)  ,

	@Alias varchar (200)  ,

	@Summary nvarchar (500)  ,

	@Description ntext   ,

	@MenuId int   ,

	@Thumbnail varchar (200)  ,

	@IsPublished bit   ,

	@OrderIndex int   ,

	@IsAllowDelete bit   ,

	@Language varchar (10)  ,

	@PublishedDate datetime   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsHot bit   
)
AS


				
				INSERT INTO [dbo].[Article]
					(
					[LocalId]
					,[Title]
					,[Alias]
					,[Summary]
					,[Description]
					,[MenuId]
					,[Thumbnail]
					,[IsPublished]
					,[OrderIndex]
					,[IsAllowDelete]
					,[Language]
					,[PublishedDate]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					,[IsHot]
					)
				VALUES
					(
					@LocalId
					,@Title
					,@Alias
					,@Summary
					,@Description
					,@MenuId
					,@Thumbnail
					,@IsPublished
					,@OrderIndex
					,@IsAllowDelete
					,@Language
					,@PublishedDate
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					,@IsHot
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Article table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Update
(

	@Id int   ,

	@LocalId nvarchar (20)  ,

	@Title nvarchar (200)  ,

	@Alias varchar (200)  ,

	@Summary nvarchar (500)  ,

	@Description ntext   ,

	@MenuId int   ,

	@Thumbnail varchar (200)  ,

	@IsPublished bit   ,

	@OrderIndex int   ,

	@IsAllowDelete bit   ,

	@Language varchar (10)  ,

	@PublishedDate datetime   ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsHot bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Article]
				SET
					[LocalId] = @LocalId
					,[Title] = @Title
					,[Alias] = @Alias
					,[Summary] = @Summary
					,[Description] = @Description
					,[MenuId] = @MenuId
					,[Thumbnail] = @Thumbnail
					,[IsPublished] = @IsPublished
					,[OrderIndex] = @OrderIndex
					,[IsAllowDelete] = @IsAllowDelete
					,[Language] = @Language
					,[PublishedDate] = @PublishedDate
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
					,[IsHot] = @IsHot
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Article table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Article] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_GetByMenuId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_GetByMenuId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_GetByMenuId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Article table through a foreign key
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_GetByMenuId
(

	@MenuId int   
)
AS


				SET ANSI_NULLS OFF
				
				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Summary],
					[Description],
					[MenuId],
					[Thumbnail],
					[IsPublished],
					[OrderIndex],
					[IsAllowDelete],
					[Language],
					[PublishedDate],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsHot]
				FROM
					[dbo].[Article]
				WHERE
					[MenuId] = @MenuId
				
				SELECT @@ROWCOUNT
				SET ANSI_NULLS ON
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_GetByAlias procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_GetByAlias') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_GetByAlias
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Article table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_GetByAlias
(

	@Alias varchar (200)  
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Summary],
					[Description],
					[MenuId],
					[Thumbnail],
					[IsPublished],
					[OrderIndex],
					[IsAllowDelete],
					[Language],
					[PublishedDate],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsHot]
				FROM
					[dbo].[Article]
				WHERE
					[Alias] = @Alias
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_GetByLocalId procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_GetByLocalId') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_GetByLocalId
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Article table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_GetByLocalId
(

	@LocalId nvarchar (20)  
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Summary],
					[Description],
					[MenuId],
					[Thumbnail],
					[IsPublished],
					[OrderIndex],
					[IsAllowDelete],
					[Language],
					[PublishedDate],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsHot]
				FROM
					[dbo].[Article]
				WHERE
					[LocalId] = @LocalId
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Article table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[LocalId],
					[Title],
					[Alias],
					[Summary],
					[Description],
					[MenuId],
					[Thumbnail],
					[IsPublished],
					[OrderIndex],
					[IsAllowDelete],
					[Language],
					[PublishedDate],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsHot]
				FROM
					[dbo].[Article]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Article_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Article_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Article_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Article table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Article_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@LocalId nvarchar (20)  = null ,

	@Title nvarchar (200)  = null ,

	@Alias varchar (200)  = null ,

	@Summary nvarchar (500)  = null ,

	@Description ntext   = null ,

	@MenuId int   = null ,

	@Thumbnail varchar (200)  = null ,

	@IsPublished bit   = null ,

	@OrderIndex int   = null ,

	@IsAllowDelete bit   = null ,

	@Language varchar (10)  = null ,

	@PublishedDate datetime   = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null ,

	@IsHot bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Summary]
	, [Description]
	, [MenuId]
	, [Thumbnail]
	, [IsPublished]
	, [OrderIndex]
	, [IsAllowDelete]
	, [Language]
	, [PublishedDate]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsHot]
    FROM
	[dbo].[Article]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([LocalId] = @LocalId OR @LocalId IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Alias] = @Alias OR @Alias IS NULL)
	AND ([Summary] = @Summary OR @Summary IS NULL)
	AND ([MenuId] = @MenuId OR @MenuId IS NULL)
	AND ([Thumbnail] = @Thumbnail OR @Thumbnail IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsAllowDelete] = @IsAllowDelete OR @IsAllowDelete IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([PublishedDate] = @PublishedDate OR @PublishedDate IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
	AND ([IsHot] = @IsHot OR @IsHot IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [LocalId]
	, [Title]
	, [Alias]
	, [Summary]
	, [Description]
	, [MenuId]
	, [Thumbnail]
	, [IsPublished]
	, [OrderIndex]
	, [IsAllowDelete]
	, [Language]
	, [PublishedDate]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsHot]
    FROM
	[dbo].[Article]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([LocalId] = @LocalId AND @LocalId is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Alias] = @Alias AND @Alias is not null)
	OR ([Summary] = @Summary AND @Summary is not null)
	OR ([MenuId] = @MenuId AND @MenuId is not null)
	OR ([Thumbnail] = @Thumbnail AND @Thumbnail is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsAllowDelete] = @IsAllowDelete AND @IsAllowDelete is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([PublishedDate] = @PublishedDate AND @PublishedDate is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	OR ([IsHot] = @IsHot AND @IsHot is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Contact table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_Get_List

AS


				
				SELECT
					[Id],
					[FullName],
					[Email],
					[Phone],
					[Description],
					[ContactType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsRead]
				FROM
					[dbo].[Contact]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Contact table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Contact]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[FullName], O.[Email], O.[Phone], O.[Description], O.[ContactType], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser], O.[IsRead]
				FROM
				    [dbo].[Contact] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Contact]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Contact table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_Insert
(

	@Id int    OUTPUT,

	@FullName nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@Phone nvarchar (20)  ,

	@Description nvarchar (500)  ,

	@ContactType varchar (20)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsRead bit   
)
AS


				
				INSERT INTO [dbo].[Contact]
					(
					[FullName]
					,[Email]
					,[Phone]
					,[Description]
					,[ContactType]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					,[IsRead]
					)
				VALUES
					(
					@FullName
					,@Email
					,@Phone
					,@Description
					,@ContactType
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					,@IsRead
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Contact table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_Update
(

	@Id int   ,

	@FullName nvarchar (50)  ,

	@Email nvarchar (50)  ,

	@Phone nvarchar (20)  ,

	@Description nvarchar (500)  ,

	@ContactType varchar (20)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@IsRead bit   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Contact]
				SET
					[FullName] = @FullName
					,[Email] = @Email
					,[Phone] = @Phone
					,[Description] = @Description
					,[ContactType] = @ContactType
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
					,[IsRead] = @IsRead
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Contact table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Contact] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Contact table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[FullName],
					[Email],
					[Phone],
					[Description],
					[ContactType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[IsRead]
				FROM
					[dbo].[Contact]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Contact_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Contact_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Contact_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Contact table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Contact_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@FullName nvarchar (50)  = null ,

	@Email nvarchar (50)  = null ,

	@Phone nvarchar (20)  = null ,

	@Description nvarchar (500)  = null ,

	@ContactType varchar (20)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null ,

	@IsRead bit   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Phone]
	, [Description]
	, [ContactType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsRead]
    FROM
	[dbo].[Contact]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([FullName] = @FullName OR @FullName IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Phone] = @Phone OR @Phone IS NULL)
	AND ([Description] = @Description OR @Description IS NULL)
	AND ([ContactType] = @ContactType OR @ContactType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
	AND ([IsRead] = @IsRead OR @IsRead IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Phone]
	, [Description]
	, [ContactType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [IsRead]
    FROM
	[dbo].[Contact]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([FullName] = @FullName AND @FullName is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Phone] = @Phone AND @Phone is not null)
	OR ([Description] = @Description AND @Description is not null)
	OR ([ContactType] = @ContactType AND @ContactType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	OR ([IsRead] = @IsRead AND @IsRead is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the Faq table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Get_List

AS


				
				SELECT
					[Id],
					[FullName],
					[Email],
					[Title],
					[Question],
					[Answer],
					[IsPublished],
					[ClientIp],
					[IsHot],
					[OrderIndex],
					[Language],
					[AnsweredDate],
					[AnsweredUser],
					[CreatedDate],
					[UpdatedDate]
				FROM
					[dbo].[Faq]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the Faq table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[Faq]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[FullName], O.[Email], O.[Title], O.[Question], O.[Answer], O.[IsPublished], O.[ClientIp], O.[IsHot], O.[OrderIndex], O.[Language], O.[AnsweredDate], O.[AnsweredUser], O.[CreatedDate], O.[UpdatedDate]
				FROM
				    [dbo].[Faq] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[Faq]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the Faq table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Insert
(

	@Id int    OUTPUT,

	@FullName nvarchar (100)  ,

	@Email nvarchar (50)  ,

	@Title nvarchar (50)  ,

	@Question nvarchar (500)  ,

	@Answer nvarchar (500)  ,

	@IsPublished bit   ,

	@ClientIp nvarchar (20)  ,

	@IsHot bit   ,

	@OrderIndex int   ,

	@Language varchar (10)  ,

	@AnsweredDate datetime   ,

	@AnsweredUser varchar (50)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   
)
AS


				
				INSERT INTO [dbo].[Faq]
					(
					[FullName]
					,[Email]
					,[Title]
					,[Question]
					,[Answer]
					,[IsPublished]
					,[ClientIp]
					,[IsHot]
					,[OrderIndex]
					,[Language]
					,[AnsweredDate]
					,[AnsweredUser]
					,[CreatedDate]
					,[UpdatedDate]
					)
				VALUES
					(
					@FullName
					,@Email
					,@Title
					,@Question
					,@Answer
					,@IsPublished
					,@ClientIp
					,@IsHot
					,@OrderIndex
					,@Language
					,@AnsweredDate
					,@AnsweredUser
					,@CreatedDate
					,@UpdatedDate
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the Faq table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Update
(

	@Id int   ,

	@FullName nvarchar (100)  ,

	@Email nvarchar (50)  ,

	@Title nvarchar (50)  ,

	@Question nvarchar (500)  ,

	@Answer nvarchar (500)  ,

	@IsPublished bit   ,

	@ClientIp nvarchar (20)  ,

	@IsHot bit   ,

	@OrderIndex int   ,

	@Language varchar (10)  ,

	@AnsweredDate datetime   ,

	@AnsweredUser varchar (50)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[Faq]
				SET
					[FullName] = @FullName
					,[Email] = @Email
					,[Title] = @Title
					,[Question] = @Question
					,[Answer] = @Answer
					,[IsPublished] = @IsPublished
					,[ClientIp] = @ClientIp
					,[IsHot] = @IsHot
					,[OrderIndex] = @OrderIndex
					,[Language] = @Language
					,[AnsweredDate] = @AnsweredDate
					,[AnsweredUser] = @AnsweredUser
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the Faq table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[Faq] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the Faq table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[FullName],
					[Email],
					[Title],
					[Question],
					[Answer],
					[IsPublished],
					[ClientIp],
					[IsHot],
					[OrderIndex],
					[Language],
					[AnsweredDate],
					[AnsweredUser],
					[CreatedDate],
					[UpdatedDate]
				FROM
					[dbo].[Faq]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.Faq_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.Faq_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.Faq_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Faq table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@FullName nvarchar (100)  = null ,

	@Email nvarchar (50)  = null ,

	@Title nvarchar (50)  = null ,

	@Question nvarchar (500)  = null ,

	@Answer nvarchar (500)  = null ,

	@IsPublished bit   = null ,

	@ClientIp nvarchar (20)  = null ,

	@IsHot bit   = null ,

	@OrderIndex int   = null ,

	@Language varchar (10)  = null ,

	@AnsweredDate datetime   = null ,

	@AnsweredUser varchar (50)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Title]
	, [Question]
	, [Answer]
	, [IsPublished]
	, [ClientIp]
	, [IsHot]
	, [OrderIndex]
	, [Language]
	, [AnsweredDate]
	, [AnsweredUser]
	, [CreatedDate]
	, [UpdatedDate]
    FROM
	[dbo].[Faq]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([FullName] = @FullName OR @FullName IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Question] = @Question OR @Question IS NULL)
	AND ([Answer] = @Answer OR @Answer IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([ClientIp] = @ClientIp OR @ClientIp IS NULL)
	AND ([IsHot] = @IsHot OR @IsHot IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([Language] = @Language OR @Language IS NULL)
	AND ([AnsweredDate] = @AnsweredDate OR @AnsweredDate IS NULL)
	AND ([AnsweredUser] = @AnsweredUser OR @AnsweredUser IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Title]
	, [Question]
	, [Answer]
	, [IsPublished]
	, [ClientIp]
	, [IsHot]
	, [OrderIndex]
	, [Language]
	, [AnsweredDate]
	, [AnsweredUser]
	, [CreatedDate]
	, [UpdatedDate]
    FROM
	[dbo].[Faq]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([FullName] = @FullName AND @FullName is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Question] = @Question AND @Question is not null)
	OR ([Answer] = @Answer AND @Answer is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([ClientIp] = @ClientIp AND @ClientIp is not null)
	OR ([IsHot] = @IsHot AND @IsHot is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([Language] = @Language AND @Language is not null)
	OR ([AnsweredDate] = @AnsweredDate AND @AnsweredDate is not null)
	OR ([AnsweredUser] = @AnsweredUser AND @AnsweredUser is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the File table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Get_List

AS


				
				SELECT
					[Id],
					[Url],
					[Title],
					[ParentId],
					[OrderIndex],
					[IsPublished],
					[FileType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[Catalog]
				FROM
					[dbo].[File]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the File table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[File]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Url], O.[Title], O.[ParentId], O.[OrderIndex], O.[IsPublished], O.[FileType], O.[CreatedDate], O.[UpdatedDate], O.[CreatedUser], O.[UpdatedUser], O.[Catalog]
				FROM
				    [dbo].[File] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[File]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the File table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Insert
(

	@Id int    OUTPUT,

	@Url nvarchar (200)  ,

	@Title nvarchar (50)  ,

	@ParentId nvarchar (20)  ,

	@OrderIndex int   ,

	@IsPublished bit   ,

	@FileType varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@Catalog varchar (50)  
)
AS


				
				INSERT INTO [dbo].[File]
					(
					[Url]
					,[Title]
					,[ParentId]
					,[OrderIndex]
					,[IsPublished]
					,[FileType]
					,[CreatedDate]
					,[UpdatedDate]
					,[CreatedUser]
					,[UpdatedUser]
					,[Catalog]
					)
				VALUES
					(
					@Url
					,@Title
					,@ParentId
					,@OrderIndex
					,@IsPublished
					,@FileType
					,@CreatedDate
					,@UpdatedDate
					,@CreatedUser
					,@UpdatedUser
					,@Catalog
					)
				
				-- Get the identity value
				SET @Id = SCOPE_IDENTITY()
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the File table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Update
(

	@Id int   ,

	@Url nvarchar (200)  ,

	@Title nvarchar (50)  ,

	@ParentId nvarchar (20)  ,

	@OrderIndex int   ,

	@IsPublished bit   ,

	@FileType varchar (10)  ,

	@CreatedDate datetime   ,

	@UpdatedDate datetime   ,

	@CreatedUser varchar (50)  ,

	@UpdatedUser varchar (50)  ,

	@Catalog varchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[File]
				SET
					[Url] = @Url
					,[Title] = @Title
					,[ParentId] = @ParentId
					,[OrderIndex] = @OrderIndex
					,[IsPublished] = @IsPublished
					,[FileType] = @FileType
					,[CreatedDate] = @CreatedDate
					,[UpdatedDate] = @UpdatedDate
					,[CreatedUser] = @CreatedUser
					,[UpdatedUser] = @UpdatedUser
					,[Catalog] = @Catalog
				WHERE
[Id] = @Id 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the File table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[File] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the File table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Url],
					[Title],
					[ParentId],
					[OrderIndex],
					[IsPublished],
					[FileType],
					[CreatedDate],
					[UpdatedDate],
					[CreatedUser],
					[UpdatedUser],
					[Catalog]
				FROM
					[dbo].[File]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.File_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.File_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.File_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the File table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.File_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Url nvarchar (200)  = null ,

	@Title nvarchar (50)  = null ,

	@ParentId nvarchar (20)  = null ,

	@OrderIndex int   = null ,

	@IsPublished bit   = null ,

	@FileType varchar (10)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null ,

	@CreatedUser varchar (50)  = null ,

	@UpdatedUser varchar (50)  = null ,

	@Catalog varchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [ParentId]
	, [OrderIndex]
	, [IsPublished]
	, [FileType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [Catalog]
    FROM
	[dbo].[File]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Url] = @Url OR @Url IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([ParentId] = @ParentId OR @ParentId IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([FileType] = @FileType OR @FileType IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
	AND ([CreatedUser] = @CreatedUser OR @CreatedUser IS NULL)
	AND ([UpdatedUser] = @UpdatedUser OR @UpdatedUser IS NULL)
	AND ([Catalog] = @Catalog OR @Catalog IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Url]
	, [Title]
	, [ParentId]
	, [OrderIndex]
	, [IsPublished]
	, [FileType]
	, [CreatedDate]
	, [UpdatedDate]
	, [CreatedUser]
	, [UpdatedUser]
	, [Catalog]
    FROM
	[dbo].[File]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Url] = @Url AND @Url is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([ParentId] = @ParentId AND @ParentId is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([FileType] = @FileType AND @FileType is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	OR ([CreatedUser] = @CreatedUser AND @CreatedUser is not null)
	OR ([UpdatedUser] = @UpdatedUser AND @UpdatedUser is not null)
	OR ([Catalog] = @Catalog AND @Catalog is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_Get_List procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_Get_List') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_Get_List
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets all records from the UserType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_Get_List

AS


				
				SELECT
					[Id],
					[Title]
				FROM
					[dbo].[UserType]
					
				SELECT @@ROWCOUNT
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_GetPaged procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_GetPaged') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_GetPaged
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Gets records from the UserType table passing page index and page count parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_GetPaged
(

	@WhereClause varchar (2000)  ,

	@OrderBy varchar (2000)  ,

	@PageIndex int   ,

	@PageSize int   
)
AS


				
				BEGIN
				DECLARE @PageLowerBound int
				DECLARE @PageUpperBound int
				
				-- Set the page bounds
				SET @PageLowerBound = @PageSize * @PageIndex
				SET @PageUpperBound = @PageLowerBound + @PageSize

				-- Create a temp table to store the select results
				CREATE TABLE #PageIndex
				(
				    [IndexId] int IDENTITY (1, 1) NOT NULL,
				    [Id] int 
				)
				
				-- Insert into the temp table
				DECLARE @SQL AS nvarchar(4000)
				SET @SQL = 'INSERT INTO #PageIndex ([Id])'
				SET @SQL = @SQL + ' SELECT'
				SET @SQL = @SQL + ' [Id]'
				SET @SQL = @SQL + ' FROM [dbo].[UserType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				IF LEN(@OrderBy) > 0
				BEGIN
					SET @SQL = @SQL + ' ORDER BY ' + @OrderBy
				END
				
				-- Only get the number of rows needed here.
				SET ROWCOUNT @PageUpperBound
				
				-- Populate the temp table
				EXEC sp_executesql @SQL

				-- Reset Rowcount back to all
				SET ROWCOUNT 0
				
				-- Return paged results
				SELECT O.[Id], O.[Title]
				FROM
				    [dbo].[UserType] O,
				    #PageIndex PageIndex
				WHERE
				    PageIndex.IndexId > @PageLowerBound
					AND O.[Id] = PageIndex.[Id]
				ORDER BY
				    PageIndex.IndexId
				
				-- get row count
				SET @SQL = 'SELECT COUNT(*) AS TotalRowCount'
				SET @SQL = @SQL + ' FROM [dbo].[UserType]'
				IF LEN(@WhereClause) > 0
				BEGIN
					SET @SQL = @SQL + ' WHERE ' + @WhereClause
				END
				EXEC sp_executesql @SQL
			
				END
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_Insert procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_Insert') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_Insert
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Inserts a record into the UserType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_Insert
(

	@Id int   ,

	@Title nvarchar (50)  
)
AS


				
				INSERT INTO [dbo].[UserType]
					(
					[Id]
					,[Title]
					)
				VALUES
					(
					@Id
					,@Title
					)
				
									
							
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_Update procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_Update') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_Update
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Updates a record in the UserType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_Update
(

	@Id int   ,

	@OriginalId int   ,

	@Title nvarchar (50)  
)
AS


				
				
				-- Modify the updatable columns
				UPDATE
					[dbo].[UserType]
				SET
					[Id] = @Id
					,[Title] = @Title
				WHERE
[Id] = @OriginalId 
				
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_Delete procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_Delete') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_Delete
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Deletes a record in the UserType table
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_Delete
(

	@Id int   
)
AS


				DELETE FROM [dbo].[UserType] WITH (ROWLOCK) 
				WHERE
					[Id] = @Id
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_GetById procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_GetById') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_GetById
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Select records from the UserType table through an index
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_GetById
(

	@Id int   
)
AS


				SELECT
					[Id],
					[Title]
				FROM
					[dbo].[UserType]
				WHERE
					[Id] = @Id
				SELECT @@ROWCOUNT
					
			

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

	

-- Drop the dbo.UserType_Find procedure
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'dbo.UserType_Find') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
DROP PROCEDURE dbo.UserType_Find
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the UserType table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.UserType_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@Title nvarchar (50)  = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [Title]
    FROM
	[dbo].[UserType]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [Title]
    FROM
	[dbo].[UserType]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([Title] = @Title AND @Title is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
SET QUOTED_IDENTIFIER ON 
GO
SET NOCOUNT ON
GO
SET ANSI_NULLS OFF 
GO

